package com.java.simple.study.tool;

import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

/**
 * @author zhoujunlin
 * @date 2022年04月05日 15:15
 * @desc
 */
@Slf4j(topic = "c.FileReader")
public class FileReader {

    public static void read(String fileName) {
        int idx = fileName.lastIndexOf(File.separator);
        String shortName = fileName.substring(idx + 1);
        try (FileInputStream fileInputStream = new FileInputStream(fileName)) {
            long start = System.currentTimeMillis();
            log.debug("read[{}] start...", shortName);
            byte[] bytes = new byte[1024];
            int n = -1;
            do {
                n = fileInputStream.read(bytes);
            } while (n != -1);
            long end = System.currentTimeMillis();
            log.debug("read[{}] end... cost:{}", shortName, (end - start));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
